﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using rbac.API.Filters;
using rbac.Contracts.DTO.Input;
using rbac.Contracts.DTO.Output;
using rbac.Contracts.Interface;
using rbac.Domain.Entity;
using rbac.Share.Consts;


namespace rbac.API.Controllers
{/// <summary>
/// 权限管理
/// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermissController : ControllerBase
    {
        private readonly IPermissService _service;

        public PermissController(IPermissService service)
        {
            _service = service;
        }
        /// <summary>
        /// 权限显示
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [HttpPost]
        [RbacAuthorize(AuthorizePolicyName.AdminAndCustomer)]
        public Results<PageListOutput<PermissOutput>> GetPermiss([FromBody]PermissInput Input)
        {
            return Results<PageListOutput<PermissOutput>>.DataResult(_service.GetPermiss(Input));
        }
        /// <summary>
        /// 权限添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [RbacAuthorize(AuthorizePolicyName.Admin)]
        public Results<int> Add([FromBody]PerInput input)
        {
            return Results<int>.DataResult(_service.Add(input));
        }
        /// <summary>
        /// 修改权限
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Results<int> Update([FromBody] PerInput input)
        {
            return Results<int>.DataResult(_service.Update(input));
        }
        /// <summary>
        /// 权限删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public Results<int> Delete(params int[] ids)
        {
            return Results<int>.DataResult(_service.Delete(ids));
        }
    }
}
